import { readUriToTextAndExplode } from "../readFileToText/openTextFile";
import { AirlineIcaoData } from "../classes/AirlineIcaoData";
import { RenderData } from "../classes/RadarRenderData";

export async function loadIcaoAirlinesFile(uri: string) {
    const reg = new RegExp('(?<code>[^\\t]*)\\t(?<name>[^\\t]*)\\t(?<callsign>[^\\t]*)\\t(?<country>.*)');
    const lines = await readUriToTextAndExplode(uri);
    for (const line of lines) {
        const match = reg.exec(line);
        if (match != null && match.groups != undefined) {
            const g = match.groups;
            const airline = new AirlineIcaoData()
            airline.code = g.code;
            airline.country = g.country;
            airline.callsign = g.callsign;
            airline.name = g.name;
            RenderData.airlineIcaoData.set(airline.code, airline);
        }
    }
}